home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / batchut / setenv13.zip / SETENV.DOC < prev    next >
Text File  |  1989-09-28  |  4KB  |  80 lines

  1. The SETENV set of routines comprise a subroutine (coded in both TurboC
  2. and Turbo Pascal) and a TurboC utility that uses the subroutine.  These
  3. utilities set the Environment block of a shell, not of the program.
  4.  
  5. First some background.  One problem with the Environment block is that a
  6. program can only access its Env block and can pass the Env block down to
  7. a lower level program.  When a shell calls a program, a copy of the
  8. shell's Env block is made.  This copy is used by the program.  When a
  9. program sets an environment variable with one of the normal "setenv"
  10. routines, this env variable is not left set when the program exits back
  11. to the shell.  The env variable is only set in the programs env block,
  12. not in the shell's.
  13.  
  14. Many programers (especially me) need a decent interactive way to get
  15. data into .BAT files.  One way to do this is with a better shell (does
  16. 4DOS handle this?) rather than command.com.  But if you are releasing
  17. software, you cannot count on a user having some wierd shell.  Thus I
  18. wrote a "setenv" that sets the shell's env block, not the program's.
  19.  
  20. This gets a little hairy.  It is relatively easy to find the primary
  21. shell's env block - just scan memory for the first env block.  But if
  22. shell A invokes shell B then you want to set shell B's env block not the
  23. primary block (which is for shell A).  Anyway the "setenv" routine looks
  24. all around memory, using all sorts of tricks to usually get the shell's
  25. env block.
  26.  
  27. A caveat - if it works once for you it will basically always work.  But
  28. make sure, if you are using other than command.com, that it does work!
  29.  
  30. Now what do we have here:
  31.         The basic subroutine is settheenv.  I have coded it in
  32.         TurboC and TurboP.
  33.  
  34.         The C prototype is:  int settheenv(char * s1, char * s2);
  35.  
  36.         in Pascal:  boolean SetTheEnv (S1, S2 : string[24]);
  37.  
  38.         s1 is the name of the env variable to set.
  39.         s2 is the value to put into that variable.
  40.  
  41.         the routine returns 0 (or True) if successful and
  42.         1 (or False) if a failure.  Remember to check for
  43.         failure.  A common failure is when the env block
  44.         is full.
  45.  
  46. I have included TurboP source, a TPU unit, TurboC source and the object.
  47. The TurboC files are called setenvs.* (setenvs means setenv subroutine).
  48.  
  49. I have also included a TurboC program which interactively asks the user
  50. a question and puts the response into a shell env variable.  This lets
  51. you, for example, have a .BAT file which asks "what is your name ?" and
  52. have the response put into an Env variable so that the .BAT file can use
  53. it.  This program also can set some system values into Env variables.
  54. (Get the current drive for example.)
  55.  
  56. The program is called setenv which is why the subroutine is called
  57. setenvs.
  58.  
  59. Two years ago I released setenv 1.1 and this setenv (1.3) is pretty much
  60. the same.  It does have a better search for the env block, but if you
  61. already have setenv and it works, this will be no surprise.  The
  62. advantage of this version is that the setenvs is broken into a separate
  63. routine so you can easily use it in your own code.
  64.  
  65. About a year ago someone released a very nice assembler version of
  66. setenv that had a different keyboard feel.  So you may want to hunt in
  67. archives and get that utility also.  I forget the author and I
  68. apoligize, he referenced me and I want to reference him.
  69.  
  70. Oh, I put a bit of work into this program, so if you want to use it
  71. commercially, please contact me, I would like some $$.  For personal
  72. use it is free.
  73.  
  74. Regards,
  75. Richard Marks
  76. 931 Sulgrave Lane
  77. Bryn MAwr, PA 19010
  78.  
  79. rmarks@KSP.unisys.COM
  80.